<?php
$searchBox = new searchEngine();

if($page == "results"){

    $searchResults = $searchBox->searchQuery($_POST['search'], $searchType);

    if(!empty($_POST['search'])){
        if(!empty($searchResults)){

            $i = 0;
            foreach($searchResults as $result)
            {
                $i++;
                if($i <= 5){
                    ?>
                    <div class="main_item">
                    <?php if($searchType == "new"){ ?>
                        <a href="page/2/news/article/<?php print($result['id'].'/'.htmlentities(strtolower($result['title']))); ?>">
                            <img src="<?php print(DATA_PATH); ?>/images/posts/post_thumbs/<?php print($result['thumb']); ?>.gif" class="main_thumb" title="<?php print($result['title']); ?>" alt="<?php print($result['title']); ?>" />
                        </a>
                        <h2>
                            <a class="black" href="page/2/news/article/<?php print($result['id'].'/'.htmlentities(strtolower($result['title']))); ?>" title="<?php print($result['title']); ?>"><?php print($result['title']); ?></a>
                        </h2>
                        <p class="nomarg"><?php print($result['shortSummary']); ?></p>
                    <?php
                    }
                    elseif($searchType == "mem"){
                        ?>
                        <a href="page/7/profile/user/<?php print($result['id']); ?>">
                            <img class="main_thumb" src="<?php print(DATA_PATH.'/images/profiles/'.strtolower($result['username']).'/avatars/'.strtolower($result['avatar'])); ?>" alt="<?php print(ucfirst($result['avatarComment'])); ?>" title="<?php print(ucfirst($result['avatarComment'])); ?>" />
                        </a>
                        <h2>
                            <a class="black" href="page/7/profile/user/<?php print($result['id']); ?>" title="<?php print($result['username']); ?>"><?php print(ucfirst($result['username'])); ?></a>
                        </h2>
                        <p class="nomarg">'.$result['profession'].'</p>
                        <p class="nomarg">'.$result['os'].'</p>
                    <?php } ?>
                    </div>
                    <div class="clear"></div>
                <?php }
            }
            //
            //            print('<table class="results" cellspacing="0">'.PHP_EOL);
            //            print('<tr class="first"><td><h3>Results for '.$_POST['search'].'</h3></td><td></td></tr>'.PHP_EOL.'');
            //
            //            else{
            //
            //                print('<tr class="'.$result['class'].'">');
            //                if($searchType == "new"){
            //                    print('<td><a href="page.php?page=news&amp;id='.$result['id'].'" title="'.$result['title'].'"><span class="time">'.$result['time'].'</span>'.$result['title'].'</a></td>');
            //                    print('<td align="right"><span class="grey">'.$result['count'].'</span></td>');
            //                }
            //                elseif($searchType == "mem"){
            //                    print('<td><a href="page.php?page=profile&amp;user='.$result['id'].'" title="'.$result['username'].'"><span class="time">'.$result['joined'].'</span>'.$result['username'].'</a></td>');
            //                    print('<td align="right"><span class="grey">'.$result['id'].'</span></td>');
            //                }
            //                print('</tr>'.PHP_EOL);
            //
            //            }
            //        }
            //
            //        print('</table>'.PHP_EOL.PHP_EOL);
        }
        elseif(empty($searchResults)){
            ?>
            <p>Aw snap, we cant seem to find anything about <span class="bold"><?php print($_POST['search']); ?></span> I guess we give up.</p>
        <?php
            }
    }
    else{
    ?>
        <p>Whoops!, looks like you forgot something there..</p>
    <?php
    }
}
?>
